<template>
<div class="page-login">
  <div class="box">
    <h1>登录</h1>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm" label-position="top">
      <el-form-item label="手机号：" prop='phone'>
        <el-input v-model="ruleForm.phone"></el-input>
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input v-model="ruleForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</div>
</template>
<script lang="ts">
import { ElForm } from 'element-ui/types/form'
import { Vue, Component } from 'vue-property-decorator'
import { login } from '@/apis/user'
// import { setToken } from '@/utils'
@Component
export default class Login extends Vue {
  ruleForm = {
    phone: '18201288771',
    password: '111111'
  }

  rules = {

  }

  submitForm (formName: any) {
    (this.$refs[formName] as ElForm).validate(async (valid: any) => {
      if (valid) {
        const data = await login(this.ruleForm)
        this.$store.commit('setUser', data)
        this.$router.push(this.$route.query.redirect as string || '/')
      }
    })
  }
}

</script>
<style lang="scss">
.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  .el-form {
    background-color: #c0c4cc;
    padding: 30px;
  }
}
</style>
